package com.tms.app.tms.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tms.app.tms.R;
import com.tms.app.tms.adapter.HistoryAdapter;
import com.tms.app.tms.ui.base.ui.BaseListActivity;
import com.tms.app.tms.ui.home.history.HistoryP;
import com.tms.app.tms.utils.SharePreferenceUtil;
import com.tms.app.tms.widget.CustomLoadMoreView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/20 0020.
 */

public class HistrorySearchActivity extends BaseListActivity {
    @BindView(R.id.toolbar_right)
    TextView toolbarRight;
    @BindView(R.id.toolbar_search_text)
    EditText toolbarSearchText;
    @BindView(R.id.toolbar_search_button)
    Button toolbarSearchButton;
    @BindView(R.id.toolbar_search_parent)
    LinearLayout toolbarSearchParent;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.swipeLayout)
    SwipeRefreshLayout swipeLayout;
    private HistoryP histtoryP=new HistoryP();
    private int indexPage=1;
    private String searchContent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history_search);
        ButterKnife.bind(this);
        histtoryP.setiView(this);
        setToolBarTitle("历史任务", -1, -1);
        toolbarRight.setVisibility(View.GONE);
        toolbarSearchParent.setVisibility(View.VISIBLE);
        searchContent=getIntent().getStringExtra("SContent");
        if (searchContent==null)
            searchContent="";
        toolbarSearchText.setText(searchContent);
        initView();
    }


    @Override
    public void onStart() {
        super.onStart();
        histtoryP.getData(token,indexPage,searchContent);
    }

    public void initView() {
        customLoadMoreView = new CustomLoadMoreView();
        adapter = new HistoryAdapter();
        adapter.setOnItemChildClickListener(histtoryP);
        adapter.setOnItemClickListener(histtoryP);
        adapter.setLoadMoreView(customLoadMoreView);
        adapter.setOnLoadMoreListener(histtoryP, recyclerView);
        LinearLayoutManager mgr = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(mgr);
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setAdapter(adapter);
        swipeLayout.setOnRefreshListener(histtoryP);
    }

    @OnClick({R.id.toolbar_search_button})
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.toolbar_search_button:
             searchContent=toolbarSearchText.getText().toString();
             histtoryP.getData(searchContent);
                break;
        }
    }
}
